﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：吕海乐 
    //
    // 文件名：MessageGet.cs
    // 文件功能描述：消息管理：收件箱列表
    // 创建标识：吕海乐2009-5-11
    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：
    //
    // 审核人：
// 审核时间：
// 审核说明：
 //----------------------------------------------------------------*/
using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Collections.Generic;
using HZ.DrugTrade.BLLFactory;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.Model;
using HZ.DrugTrade.Model.Enum;

namespace HZ.DrugTrade.Web.Admin.MessageManage
{
    public partial class MessageGet : BasePage
    {
        public MessageGet()
        {
            this.ModuleNo = Module.消息管理.ToString();
            this.PageOperateType = OperateType.消息列表.ToString();
        }

        IBLL_Message im = Factory.BLL_Message();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                rblMessageType_SelectedIndexChanged(sender, e);
            }
        }

        /// <summary>
        /// 绑定所有发出的消息
        /// </summary>
        private void SetBind()
        {
            int totalRecord = 0;
            //AspNetPager1.PageSize = Constants.GRIDVIEW_PAGE_SIZE;
            IList<Model.View.Message> lstMessage = new List<Model.View.Message>();
            switch (rblMessageType.SelectedValue)
            {
                case"M1":
                    lstMessage = im.GetMessage(new Model.Query.Message() { SortFields = "SendTime DESC" }, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalRecord);
                    break;
                case "M2":
                    lstMessage = im.GetMessageSent(new Model.Query.Message() { SortFields = "SendTime DESC" }, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalRecord);
                    break;
                default:
                    break;
            }
            AspNetPager1.RecordCount = totalRecord;
            gvwMsgList.DataSource = lstMessage;
            gvwMsgList.DataBind();

        }

        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {
            SetBind();
        }

        /// <summary>
        /// 绑定信息的状态
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvwMsgList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Literal ltrStatus = e.Row.FindControl("ltrStatus") as Literal;
                if (ltrStatus.Text == "0")
                {
                    ltrStatus.Text = "未阅读";
                }
                else if (ltrStatus.Text == "1")
                {
                    ltrStatus.Text = "已阅读";
                }
                else if (ltrStatus.Text == "2")
                {
                    ltrStatus.Text = "已回复";
                }
            }
        }

        protected void rblMessageType_SelectedIndexChanged(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
            SetBind();
        }

    }
}
